package com.cl.master.controller;

import com.cl.master.common.Result;
import com.cl.master.domain.SewageStandard;
import com.cl.master.service.impl.SewageStandardServiceImpl;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Collection;
import java.util.List;
import java.util.Map;

/**
 * @Author xc
 * @Date 2023/4/26 15:34
 * @Version 1.0
 */
@Controller
//注解api说明该类需要生成api文档
@Api("企业排污信息模块API文档")
public class SewageStandardController {

    @Autowired
    SewageStandardServiceImpl standardService;

    @GetMapping("/sewage/page/{startPage}")
    public String getSewage(Model model, @PathVariable(value = "startPage") int startPage){
        Collection<SewageStandard> allInfoByCode = standardService.getAllInfo(startPage);
        System.out.println(startPage);
        model.addAttribute("allInfoByCode",allInfoByCode);
        model.addAttribute("startPage",startPage);
        return "manage/members";
    }

    @GetMapping("/sewage/{code}")
    public String getSewageByCode(Model model, @PathVariable(value = "code") String code) {
        Collection<SewageStandard> infoByCode = standardService.getInfoByCode(code);
        model.addAttribute("allInfoByCode",infoByCode);
        return "manage/members";
    }
    //获得相关所有的数据信息
    @RequestMapping("/sewage/getEnterpriseData")
    @ResponseBody
    public Result getEnterpriseData(){
        List<Map<String,Object>> data = standardService.getEnterpriseData();
        Result result = Result.success(data);
        return result;
    }

}

